package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealMapper {

    /**
     * 根据分类查询套餐
     * @param id
     * @return
     */
    @Select("select count(1) from setmeal where category_id = #{id}")
    Integer countAboutCategory(Long id);

    /**
     * 根据菜品查询套餐
     * @param id
     * @return
     */
    @Select("select count(1) from setmeal_dish where dish_id = #{id};")
    Integer countAboutDish(Long id);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    void insertSetMeal(Setmeal setmeal);

    /**
     * 新增套餐对应的菜品
     * @param setmealDishes
     */
    void insertSetMealDishes(List<SetmealDish> setmealDishes);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageList(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal findById(Long id);

    /**
     * 删除套餐和菜品的对应关系
     * @param ids
     */
    void deleteSetMealDishes(List<Long> ids);

    /**
     * 删除套餐
     * @param ids
     */
    void deleteSetMeal(List<Long> ids);

    /**
     * 查询套餐菜品信息
     * @param setmealId
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    List<SetmealDish> findDishes(Long setmealId);

    /**
     * 编辑菜品
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 删除原本的菜品和套餐对应关系
     * @param setmealId
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void deleteSetMealDish(Long setmealId);

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId} and status = 1")
    List<Setmeal> findByCategoryId(Integer categoryId);

    /**
     * 根据套餐id查询对应的菜品
     */
    @Select("select * from dish where id = #{dishId}")
    List<Dish> dishesBySetMealId(Long dishId);

    /**
     * 根据套餐状态查询套餐数量
     * @param status
     * @return
     */
    @Select("select count(1) from setmeal where status = #{status}")
    Integer countByStatus(Integer status);
}
